<template>
	<view>
		<!-- 修改密码 -->
		<view class="changepay">
			{{type.payPassword==0?'设置支付密码':'修改支付密码'}}
		</view>
		<!-- 输入支付密码 -->
		<view class="enterpassword">
			{{type.payPassword==0?'请输入新支付密码':'请输入支付密码,以验证身份'}}
		</view>
		<one-input  @finish="finishedOne"   type='box' :maxlength='6' class="input" color='#333333'></one-input>
		<view class="button center f30 cfff" v-if="payPassword.length>5||oldPayPassword>5" @tap="updatePayPassword()">完成</view>
	</view>
</template>

<script>
	import oneInput from '../../components/myp-one/myp-one.vue';
	import md5 from '../../common/md5.min.js'
	export default {
		data() {
			return {
				payPassword:'',
				oldPayPassword:'',
				type:uni.getStorageSync('userinfo')
			}
		},
		components: {
			oneInput
		},
		methods: {
			finishedOne(e){
				// 首次设置支付密码
				if(this.type.payPassword==0){
					this.oldPayPassword='0'
					this.payPassword=e
				}else{
					this.oldPayPassword=e
				}
			},
			updatePayPassword(){
				let parems={
					oldPayPassword:md5(this.oldPayPassword),
					payPassword:md5(this.payPassword)
				}
				if(this.payPassword==''){
					delete parems.payPassword
				}
				this.$ajax(this.apiList.updatePayPassword,parems ).then(res => {
					if(this.type.payPassword==0){
						this.type.payPassword=md5(this.payPassword)
						uni.setStorageSync('userinfo',this.type)
						this.$sToast('修改成功')
						this.$back(1,1500)
					}else{
						this.$open('./user-change-pay-next?oldPayPassword='+this.oldPayPassword)
					}
				});
			}
		}
	}
</script>

<style>
	.input{
		margin-top: 69rpx;
		color: #333333;
	}
	
	.changepay {
		color: #666;
		padding-top: 61rpx;
		text-align: center;
		font-size:60rpx;
	}
	
	.enterpassword {
		color: #666;
		padding: 29rpx 0 71rpx;
		text-align: center;
		font-size:26rpx;
	}
	
	.button {
		margin-top: 20rpx;
		width: 616rpx;
		height: 80rpx;
		line-height: 80rpx;
		background: #0297FE;
		border-radius:4rpx;
		margin: 19rpx auto;
	}
	
	page{
		background: #F3F3F3;
	}
</style>
